package com.example.sentinel.controller;

import lombok.SneakyThrows;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.CompletableFuture;

@RestController
public class HelloController {

    //    @SentinelResource(value = "/hi", blockHandler = "")
    @SneakyThrows
    @RequestMapping("/hi")
    public String sayHi() {
        System.out.println("当前线程：" + Thread.currentThread().getName());
        Thread.sleep(10 * 60 * 1000);

        CompletableFuture<Integer> completableFuture = CompletableFuture.supplyAsync(() -> {
            try {
                Thread.sleep(1000);
                System.out.println("执行异步方法");
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("异步方法执行完成");
            return 123;
        });

        completableFuture.thenAccept((r) -> {
            System.out.println("第一个异步方法执行完，返回：" + r);
        });


        return "Hi,World.";
    }

}